import { BaseSkill } from '../BaseSkill';
import { DamageType, SkillType } from '../../types';
import { General } from '../../models/General';
import { Battle } from '../../models/Battle';

export class WangSiXiangZhu extends BaseSkill {
  private readonly HEAL_RATIO = 0.2;
  private readonly LOW_HP_THRESHOLD = 0.3;

  constructor() {
    super(
      'wangSiXiangZhu',
      '忘私相助',
      SkillType.Passive,
      DamageType.None,
      0.8,  // 80% 基础触发概率
      0,    // 无CD
      1     // 1回合持续
    );
  }

  execute(source: General, battle: Battle): void {
    const currentProb = source.troops / source.maxTroops < this.LOW_HP_THRESHOLD ? 1 : this.probability;
    if (Math.random() > currentProb) return;

    const allies = battle.getAllies(source)
      .filter(ally => ally !== source)
      .sort(() => Math.random() - 0.5)
      .slice(0, 2);

    allies.forEach(ally => {
      ally.addEffect({
        type: 'healing',
        value: ally.maxTroops * this.HEAL_RATIO,
        duration: 1,
        stackable: true
      });
    });
  }
}
